<?php


namespace app\admin\business;


use app\common\model\Notice;

class noticeBus
{
    public $noticeMode = null;
    public function __construct()
    {
        $this->noticeMode = new Notice();
    }
    public function addNews($data){
        $sessionData = session(config("admin.session_admin"));
        $auto = [
            "auto"=>$sessionData['name']
        ];
        $data = array_merge($auto,$data);
        $result = $this->noticeMode->addNotice($data);
        return $result;
    }
    public function getNoticeList($current_page,$num){
        $result = $this->noticeMode->getList($current_page,$num);
        if(empty($result)){
            throw new \think\Exception('未查询到数据');
        }
        return $result;
    }
    public function getNoticeDetail($id){
        $result = $this->noticeMode->getDetailById($id);
        if(empty($result)){
            throw new \think\Exception('未查到该内容');
        }
        return $result;
    }
    public function updateNotice($data){
        $id = $data['id'];

        $data = array_diff($data,[$id]);

        $result = $this->noticeMode->updateNotice($id,$data);
        if(empty($result)){
            throw new \think\Exception('内容未更改，请检查数据');
        }
        return $result;
    }
    public function changeStatus($data){
        $id = $data['id'];
        $data = array_diff($data,[$id]);
        $result = $this->noticeMode->updateNotice($id,$data);
        if(empty($result)){
            throw new \think\Exception('状态未更改');
        }
        return $result;
    }
    public function removeNotice($id){
        $result = $this->noticeMode->removeNotice($id);
        if(empty($result)){
            throw new \think\Exception("未查到删除的信息或者改信息已经删除");
        }
        return $result;
    }

}